package com.example.lasttrain;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

public class MenuButtonBar extends LinearLayout {
	
	Context context;
	View view;
	
	Button newTrain, viewLines, trainList, settings;
	
	public MenuButtonBar(Context context) {
		super(context);
		init(context);
	}
	
	public MenuButtonBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}
	
	public MenuButtonBar(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}

	private void init(Context context){
		
		this.context = context;
		LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		view = layoutInflater.inflate(R.layout.menu_button_bar, this);
		
		newTrain = (Button)findViewById(R.id.btn_new_last_train);
		viewLines = (Button)findViewById(R.id.btn_view_lines);
		trainList = (Button)findViewById(R.id.btn_train_list);
		settings = (Button)findViewById(R.id.btn_settings);
		
		ButtonBarListener buttonBarListener = new ButtonBarListener();
		newTrain.setOnClickListener(buttonBarListener);
		viewLines.setOnClickListener(buttonBarListener);
		trainList.setOnClickListener(buttonBarListener);
		settings.setOnClickListener(buttonBarListener);
		
		if(context.getClass().equals(ListActivity.class))
			trainList.setEnabled(false);
		if(context.getClass().equals(CreateEditActivity.class))
			newTrain.setEnabled(false);
		if(context.getClass().equals(DetailActivity.class))
			newTrain.setEnabled(false);
		if(context.getClass().equals(RouteViewActivity.class))
			viewLines.setEnabled(false);
		if(context.getClass().equals(AlarmActivity.class))
			settings.setEnabled(false);
		
	}
	
	
	private void moveToCreateActivity(){
		Intent intent = new Intent(context, CreateEditActivity.class);
		context.startActivity(intent);
	}
	
	private void moveToAlarmActivity(){
		Intent intent = new Intent(context, AlarmActivity.class);
		context.startActivity(intent);
	}
	
	private void moveToMailSettingActivity(){
		Intent intent = new Intent(context, MailSettingActivity.class);
		context.startActivity(intent);
	}
	
	private void moveToRouteViewActivity(){
		Intent intent = new Intent(context, RouteViewActivity.class);
		context.startActivity(intent);
	}
	
	private void moveToListActivity(){
		Intent intent = new Intent(context, ListActivity.class);
		context.startActivity(intent);
	}
	
	public class ButtonBarListener implements OnClickListener{
    	public void onClick(View v){
			switch(v.getId()){
			case R.id.btn_new_last_train:
				moveToCreateActivity();
				break;
			case R.id.btn_view_lines:
				moveToRouteViewActivity();
				break;
			case R.id.btn_train_list:
				moveToListActivity();
				break;
			case R.id.btn_settings:
				moveToMailSettingActivity();
				break;
			default:
				break;
			}
    	}
    }

}
